package com.kotlin.zds.base

import android.os.Bundle
import android.view.View
import android.widget.TextView
import com.alibaba.android.arouter.launcher.ARouter
import com.kotlin.zds.R
import com.xuexiang.xui.widget.dialog.LoadingDialog
import com.zds.support.base.SupportBaseActivity

/**
 * Author: zds
 * Date: 2022/6/10 18:33
 * Description: 基类
 * Version: v1.0
 */
abstract class BaseActivity : SupportBaseActivity() {
    private var mDialog: LoadingDialog?=null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ARouter.getInstance().inject(this)
    }
    override fun initActionBarView() {
        super.initActionBarView()
        val btnBack: View? = findViewById(R.id.btnBack)
        btnBack?.setOnClickListener { onBackPressed() }
        setActionBarTitle()
    }

    private fun setActionBarTitle() {
        val tvTitle: View? = findViewById(R.id.tvTitle)
        if (tvTitle != null && tvTitle is TextView) {
            tvTitle.setText(title)
        }
    }

    override fun setTitle(titleId: Int) {
        super.setTitle(titleId)
        setActionBarTitle()
    }

    override fun setTitle(title: CharSequence?) {
        super.setTitle(title)
        setActionBarTitle()
    }

    /**
     * 显示对话框
     */
    protected fun showDialog(){
        mDialog?.show()
    }

    /**
     * 隐藏对话框
     */
    protected fun dismissDialog(){
        mDialog?.dismiss()
    }
}